// =====================================================================================
// 
//       Filename:  pack.cpp
// 
//    Description:  
// 
//        Version:  1.0
//        Created:  23.03.2010 16:42:33
//       Revision:  none
//       Compiler:  g++
// 
//         Author:  Dmitriy Serdyuk (), serdyuk.dmitriy@gmail.com
//        Company:  
// 
// =====================================================================================

#include "pack.h"
#include <algorithm>

std::ostream & operator<<(std::ostream & os, Card & c){
    if (c.mySuit == hearts) {
        os << "h";
    }
    if (c.mySuit == diamonds) {
        os << "d";
    }
    if (c.mySuit == clubs) {
        os << "c";
    }
    if (c.mySuit == spades) {
        os << "s";
    }
    if (c.myRange == A) {
        os << 'A';
    }
    if (c.myRange == K) {
        os << 'K';
    }
    if (c.myRange == Q) {
        os << 'Q';
    }
    if (c.myRange == J) {
        os << 'J';
    }
    if (c.myRange == f10) {
        os << 10;
    }
    if (c.myRange == f9) {
        os << 9;
    }
    if (c.myRange == f8) {
        os << 8;
    }
    if (c.myRange == f7) {
        os << 7;
    }
    if (c.myRange == f6) {
        os << 6;
    }
    if (c.myRange == f5) {
        os << 5;
    }
    if (c.myRange == f4) {
        os << 4;
    }
    if (c.myRange == f3) {
        os << 3;
    }
    if (c.myRange == f2) {
        os << 2;
    }
    os << ' ';
    return os;
}

std::ostream & operator<<(std::ostream & os, Cards & c){
    for (unsigned int i = 0; i < c.size(); ++i) {
        os << c[i];
    }
    os << '\n';
    return os;
}

// =====================================================================================
//                                     Pack
// =====================================================================================
Pack::Pack(){
    reset();
}

void Pack::shuffle(){
    std::random_shuffle(myCards.begin(), myCards.end());
}

const Card Pack::getCard(){
    Card c = myCards.back();
    myCards.pop_back();
    return c;
}

void Pack::reset(){
    myCards.clear();
    Card card;
    for(int i; i < NUM_OF_SUITS; ++i){
        for (int j = 0; j < NUM_OF_RANGES; ++j) {
            
            card.mySuit = (SUITS)i;
            card.myRange = (RANGES)j;
            myCards.push_back(card);
        }
    }
}


